package com.qf.lanzhou.blog.api.dao.Impl;

import com.qf.lanzhou.blog.api.dao.CollectCountDao;
import com.qf.lanzhou.blog.api.pojo.entity.Collect;
import com.qf.lanzhou.blog.api.util.DruidUtil;
import org.apache.commons.dbutils.*;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @Author jian
 * @Date 2020/12/17 15:55
 * @JDK 1.8
 * @Version 1.0
 */
public class CollectCountDaoimpl implements CollectCountDao {
    private QueryRunner queryRunner = new QueryRunner(DruidUtil.getDataSource());
    @Override
    public Collect select(String userId) {
        String sql="SELECT count(user_id) as count FROM t_collect where user_id=? and  collect_status=1";
        BeanProcessor bean = new GenerousBeanProcessor();
        RowProcessor processor = new BasicRowProcessor(bean);
        try {
            return queryRunner.query(sql,new BeanHandler<Collect>(Collect.class),userId);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
}
